﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModBot.ConfigBuilder.Providers;

namespace ModBot.ConfigBuilder.Forms
{
    public partial class HealInstanceForm : Form
    {
        public enum HealGemOption
        {
            alt, 
            ability, 
            item, 
            script, 
            potionbelt        
        }

        public HealSettingInstanceProvider HealSettingInstanceProvider { get; set; }

        public Boolean IsCancelled { get; set; }

        public HealInstanceForm()
        {
            InitializeComponent();
            this.IsCancelled = true;

            if (Globals.SpellDatabaseProvider != null && Globals.SpellDatabaseProvider.Spells != null)
            {

                healInstanceSpellCombobox.DataSource = Globals.SpellDatabaseProvider.Spells;
            }

            healInstanceGemCombobox.Items.Add("");
            foreach(string name in Enum.GetNames(typeof(HealGemOption)))
            {
                healInstanceGemCombobox.Items.Add(name);
            }
            
            
        }

        public void LoadHealInstance(HealSettingInstanceProvider provider)
        {
            if (provider.Index <= 0) throw new InvalidOperationException("Attempt to load provider without first setting Index value.");
            this.HealSettingInstanceProvider = provider;

            LoadContent();
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            SaveContent();
        }

        private void LoadContent()
        {
            try
            {
                healInstanceGemCombobox.Text = HealSettingInstanceProvider.AHGem;
                healInstanceSpellCombobox.Text = HealSettingInstanceProvider.AHSpell;
                healInstanceSpellFociTextbox.Text = HealSettingInstanceProvider.AHSpellFoci.ToString();
                healInstanceDurationModTextbox.Text = HealSettingInstanceProvider.AHDurMod.ToString("00");
                healInstanceMinManaTextbox.Text = HealSettingInstanceProvider.AHSpellMinMana.ToString();
                healInstanceAliasTextbox.Text = HealSettingInstanceProvider.AHSpellAlias;
                healInstanceAnnounceTextbox.Text = HealSettingInstanceProvider.AHAnnouce.ToString();
                healInstanceTargetCountTextbox.Text = HealSettingInstanceProvider.AHTarCnt.ToString();
                healInstanceTargetTypeControl.TargetTypeText = HealSettingInstanceProvider.AHClass;
                healInstancePreConditionCheckbox.Checked = HealSettingInstanceProvider.AHPreCondition;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error saving loading instance object. \r\n\r\n " + ex.Message, "General load error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            }
        }

        private void SaveContent()
        {
            try
            {
                HealSettingInstanceProvider.AHGem = healInstanceGemCombobox.Text;
                HealSettingInstanceProvider.AHSpell = healInstanceSpellCombobox.Text;
                HealSettingInstanceProvider.AHSpellFoci = healInstanceSpellFociTextbox.Text;
                HealSettingInstanceProvider.AHDurMod = Convert.ToInt32(healInstanceDurationModTextbox.Text);
                HealSettingInstanceProvider.AHSpellMinMana = Convert.ToInt32(healInstanceMinManaTextbox.Text);
                HealSettingInstanceProvider.AHSpellAlias = healInstanceAliasTextbox.Text;
                HealSettingInstanceProvider.AHAnnouce = healInstanceAnnounceTextbox.Text;
                HealSettingInstanceProvider.AHTarCnt = Convert.ToInt32(healInstanceTargetCountTextbox.Text);
                HealSettingInstanceProvider.AHClass = healInstanceTargetTypeControl.Text;
                HealSettingInstanceProvider.AHPreCondition = healInstancePreConditionCheckbox.Checked;

                this.IsCancelled = false;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error saving heal instance object. \r\n\r\n " + ex.Message, "General save error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            }
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.IsCancelled = true;
            this.Close();
        }

     

    }
}
